// 动态加载CSS和JS文件
let loadingStyle = {
	meta: function() {
		document.write('<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">');
	},
	css: function(path) {
		if (!path || path.length == 0) {
			console.log('path没有的情况下 css *** ', path);
		}
		document.write('<link rel="stylesheet" type="text/css" href="' + path + '">');
	},
	js: function(path, charset) {
		if (!path || path.length === 0) {
			console.log('path没有的情况下 js *** ', path);
		}
		document.write('<script charset="' + (charset ? charset : "utf-8") + '" src="' + path + '"></script>');
	}
}

function getPath() {
	let path = window.document.location.href;	//取得当前URL
	let pathName = window.document.location.pathname;	//取得主机地址后的目录
	let post = path.indexOf(pathName);	//取得主机端口号
	let hostPath = path.substring(0, post);	//取得主机地址
	let name = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);	//取得项目名
	let projectName = hostPath + name;	//主机地址+项目名
	console.log('获取的项目路径 *** ', projectName);
	return projectName;
}

// 引用JS和CSS头文件
var rootPath = getPath(); //项目路径

//动态生成meta
// loadingStyle.meta();

//动态加载项目 JS文件
loadingStyle.js(rootPath + "/js/jquery-1.11.3.js", "utf-8");
loadingStyle.js(rootPath + "/js/vue.min.js", "utf-8");

//动态加载项目 CSS文件
loadingStyle.css(rootPath + "/css/reset.css");
loadingStyle.css(rootPath + "/css/index.css");
document.writeln("<link rel=\'stylesheet\' type=\'text/css\' href=\'http://at.alicdn.com/t/font_2033413_2l4s0rdpla1.css\' />");

// 动态加载html
/* 
function headerDiv() {
	$('.container').append("<div class='header'></div>");
	$('.header').load(getPath() + 'xxx/header.html')
}
headerDiv();
*/

